package com.juku2024.juku.adapter

import com.chad.library.adapter.base.BaseDelegateMultiAdapter
import com.chad.library.adapter.base.delegate.BaseMultiTypeDelegate
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.juku2024.juku.R
import com.juku2024.juku.model.EpisodesResponse
import com.juku2024.juku.tools.Constants

class DialogEpisodeAdapter(episodes: ArrayList<EpisodesResponse>?) :
    BaseDelegateMultiAdapter<EpisodesResponse, BaseViewHolder>(episodes) {

    // 设置当前剧集列表的专辑的分类
    var category: Int = Constants.VIDEO_CATEGORY_ALBUM

    init {
        setMultiTypeDelegate(object : BaseMultiTypeDelegate<EpisodesResponse>() {
            override fun getItemType(data: List<EpisodesResponse>, position: Int): Int {
                return category
            }
        })

        getMultiTypeDelegate()?.apply {
            addItemType(2, R.layout.item_dialog_episode_small)
            addItemType(3, R.layout.item_dialog_episode_large)
            addItemType(1, R.layout.item_dialog_episode_movie)
        }
    }

    override fun convert(holder: BaseViewHolder, item: EpisodesResponse) {
        // 设置当前视频播放状态
        val bgRes = if (item.isPlaying) {
            R.drawable.shape_controller_episode_select
        } else {
            R.drawable.shape_controller_episode
        }
        // 设置狙击数
        holder.setText(R.id.tv_episode, item.title)
            .setBackgroundResource(R.id.tv_episode, bgRes)


        holder.setGone(R.id.epi_played, !item.isPlayed)
        // 设置解锁角标, 有解锁广告同时不能是下载剧集
        holder.setGone(R.id.epi_top_icon, !item.isLockVideoAd)


//        // 设置下载信息
//        val downloadResId = if (item.isDownloaded) {
//            R.drawable.ic_dl_finish
//        } else {
//            0
//        }
//        holder.setGone(R.id.downloadStatus, downloadResId == 0)
//            .setBackgroundResource(R.id.downloadStatus, downloadResId)
    }


}